package com.yllt4cloud.common.ddbase.containers;

import org.apache.commons.lang.StringUtils;

import java.util.concurrent.ConcurrentHashMap;

/**
 * 
 * <p><b>类名称：</b>AuthorityTokenContainer </p>
 * <p><b>类描述：</b>存放认证数据信息</p>
 * <p><b>日期：</b>2016-2-25 下午7:31:27</p>
 * @author yaozq
 */
public class AuthorityTokenContainer {

	private static AuthorityTokenContainer authorityTokenContainer = null;
	
	private ConcurrentHashMap<String, String> tokenMap = new ConcurrentHashMap<String, String>();
	
	//获取实例
	public static AuthorityTokenContainer instance(){
		if (null == authorityTokenContainer) {
            synchronized (AuthorityTokenContainer.class) {
                if (null == authorityTokenContainer) {
                	authorityTokenContainer = new AuthorityTokenContainer();
                }
            }
        }
        return authorityTokenContainer;
	}
	
	//加入数据
	public void addToken(String token, String value){
		tokenMap.put(token, value);
	}
	
	//获取数据  如果存在则删除原有数据
	public String getValue(String token){
		String value = tokenMap.get(token);
		
		if(value != null && StringUtils.isEmpty(value)){
			removeValue(token);
		}
		
		return value;
	}
	
	//删除数据
	public void removeValue(String token){
		tokenMap.remove(token);
	}
	
	//清空数据
	public void clear(){
		tokenMap.clear();
	}
}
